//
//  LSQNoPicCell.m
//  Style
//
//  Created by dllo on 15/10/7.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "LSQNoPicCell.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
@implementation LSQNoPicCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
   
        if (self) {
            
            self.labelAuthor = [[UILabel alloc]init];
            [self addSubview:self.labelAuthor];
            self.labelAuthor.font = [UIFont systemFontOfSize:15];
            
            
            self.labelTime = [[UILabel alloc]init];
            [self addSubview:self.labelTime];
            self.labelTime.font = [UIFont systemFontOfSize:11];
            self.labelTime.textColor = [UIColor darkGrayColor];
            
            self.labelContent = [[UILabel alloc]init];
            [self addSubview:self.labelContent];
            self.labelContent.numberOfLines = 0;
            self.labelContent.font =[UIFont systemFontOfSize:15];
            self.labelContent.textColor = [UIColor blackColor];
            
            self.imageViewTime = [[UIImageView alloc]init];
            [self addSubview:self.imageViewTime];
            self.imageViewTime.image = [UIImage imageNamed:@"time.png"];
            

        }
        return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.labelAuthor mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(20);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width , 30));
        
        make.top.equalTo(self).with.offset(5);
        
        
    }];
    
    [self.labelTime mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(40);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width , 20));
        
        make.top.equalTo(self.labelAuthor).with.offset(24);
    }];
    
    [self.imageViewTime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(21);
        
        make.size.mas_equalTo(CGSizeMake(16 , 16));
        
        make.top.equalTo(self.labelAuthor).with.offset(26);
        
    }];

    //根据文字的大小,计算出文本的尺寸
    //还需要执行一个尺寸(375,0)
    //第三个参数,计算高度需要根据字体的哪个特征来确定
    //NSLog(@"%lf",self.frame.size.width);
    NSDictionary *fontDic=[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15],NSFontAttributeName, nil];
    CGRect rect = [self.labelContent.text boundingRectWithSize:CGSizeMake(self.frame.size.width - 30 , 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
    
    [self.labelContent mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width - 30, rect.size.height + 20));
        
        make.top.equalTo(self.imageViewTime).with.offset(15);
        
        
    }];


}

-(void)setModel:(LSQpushModel *)model
{
    
    _model = model;
    
    self.labelAuthor.text = [NSString stringWithFormat:@"from:%@",self.model.author];

    self.labelContent.text = self.model.content;
    
    
    self.labelTime.text = self.model.time;

    [self.imageViewThumb sd_setImageWithURL:[NSURL URLWithString:self.model.thumb] placeholderImage:[UIImage imageNamed:@"zhanweitu.png"]];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
